home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / nuf210.arc / SELECT.C < prev    next >
C/C++ Source or Header  |  1990-06-14  |  7KB  |  240 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <dos.h>
  4. #include <sys\stat.h>
  5. #include <dir.h>
  6. #include <io.h>
  7.  
  8. #include "nufind.h"
  9. #include "queue.h"
  10.  
  11. struct DateSel {
  12.     unsigned Date;
  13.     int      Swt;
  14.     };
  15.  
  16. int  Match (char *Str, char *Pat);
  17. char *PrintNumber (long Number);
  18. int Copy (INFO_BLOCK *Name);
  19. int Move (INFO_BLOCK *Name);
  20. void Execute (char *Name);
  21. int CheckPath (QUE_DEF *Q, char *Name);
  22. void FixDirRef (char *Name, char *Ref, char *Temp);
  23.  
  24.  int
  25. Select (INFO_BLOCK *Name) {
  26.     extern QUE_DEF Paths, IncNameQueue, ExcNameQueue;
  27.     extern QUE_DEF IncPathQueue, ExcPathQueue;
  28.     extern int AttrSwt, NotAttrSwt, SizeSwt, TreeSwt;
  29.     extern char AttrMask, NotAttrMask;
  30.     extern char *ExistRef, *NotExistRef, *CompRef, *NotCompRef;
  31.     extern INFO_BLOCK *LT_Ref, *LE_Ref, *GT_Ref, *GE_Ref;
  32.     extern INFO_BLOCK *LT_DateRef, *LE_DateRef, *GT_DateRef, *GE_DateRef;
  33.     extern struct DateSel Since, Before;
  34.     extern int BaseLength;
  35.     extern long Size;
  36.  
  37.     QUE_ENTRY *t;
  38.     char *p;
  39.     int Result = 0;
  40.     char Temp[66];
  41.     struct ffblk DirBlk;
  42.  
  43.     if ( (p = strrchr(Name->Name, '\\')) != NULL) ++p;
  44.     else p = Name->Name;
  45.     if (IncNameQueue.Count) {
  46.         for (t=IncNameQueue.Head; t != NULL; t = t->Next)
  47.             if (Match(p, t->Body)) break;
  48.         if (t == NULL) Result = 0;
  49.         else Result = 1;
  50.         }
  51.     else Result = 1;
  52.     if (ExcNameQueue.Count) {
  53.         for (t=ExcNameQueue.Head; t != NULL; t = t->Next)
  54.             if (Match(p, t->Body)) {
  55.                 Result = 0;
  56.                 break;
  57.                 }
  58.         }
  59.     if (IncPathQueue.Count) {
  60.         if (CheckPath(&IncPathQueue, Name->Name)) Result = 1;
  61.         }
  62.     if (ExcPathQueue.Count) {
  63.         if (CheckPath(&ExcPathQueue, Name->Name)) Result = 0;
  64.         }
  65.     if (ExistRef != NULL) {
  66.         if ( (Name->Attrib & (FA_DIREC | FA_LABEL)) == 0 )  {
  67.             FixDirRef(Name->Name, ExistRef, Temp);
  68.             if (findfirst(Temp, &DirBlk, 0xFF)) Result = 0;
  69.             else if ( (DirBlk.ff_attrib & FA_DIREC) != 0) Result = 0;
  70.             }
  71.         }
  72.     if (NotExistRef != NULL) {
  73.         if ( (Name->Attrib & (FA_DIREC | FA_LABEL)) == 0 )  {
  74.             FixDirRef(Name->Name, NotExistRef, Temp);
  75.             if ( !findfirst(Temp, &DirBlk, 0xFF)
  76.                && ( (DirBlk.ff_attrib & FA_DIREC) == 0) ) Result = 0;
  77.            }
  78.         }
  79.     if (CompRef != NULL) {
  80.         if ( (Name->Attrib & (FA_DIREC | FA_LABEL)) == 0 ) {
  81.             FixDirRef(Name->Name, CompRef, Temp);
  82.             if ( findfirst(Temp, &DirBlk, 0xFF)
  83.                 || ((DirBlk.ff_attrib & FA_DIREC)) == 0 ) Result = 0;
  84.             else
  85.                 if ( (Name->Size != DirBlk.ff_fsize)
  86.                      || (Name->FDate.Date != DirBlk.ff_fdate)
  87.                      || (Name->FTime.Time != DirBlk.ff_ftime)
  88.                    ) Result = 0;
  89.            }
  90.        }
  91.     if (NotCompRef != NULL) {
  92.         if ( (Name->Attrib & (FA_DIREC | FA_LABEL)) == 0 ) {
  93.             FixDirRef(Name->Name, NotCompRef, Temp);
  94.             if ( findfirst(Temp, &DirBlk, 0xFF)
  95.                 && ((DirBlk.ff_attrib & FA_DIREC)) == 0 ) Result = 0;
  96.             else
  97.                 if ( (Name->Size != DirBlk.ff_fsize)
  98.                      && (Name->FDate.Date != DirBlk.ff_fdate)
  99.                      && (Name->FTime.Time != DirBlk.ff_ftime)
  100.                    ) Result = 0;
  101.            }
  102.        }
  103.     if (Result == 0) return(0);
  104.     if (AttrSwt)
  105.         if ( (Name->Attrib & AttrMask) == 0) return(0);
  106.     if (NotAttrSwt)
  107.         if ( (Name->Attrib & NotAttrMask) != 0) return(0);
  108.     if (Since.Swt)
  109.         if (Name->FDate.Date < Since.Date) return(0);
  110.     if (Before.Swt)
  111.         if (Name->FDate.Date >= Before.Date) return(0);
  112.     if (SizeSwt) {
  113.         if (SizeSwt < 2 && Name->Size < Size) return(0);
  114.         if (SizeSwt > 1 && Name->Size > Size) return(0);
  115.         }
  116.     if (LT_Ref != NULL) {
  117.         if (Name->FDate.Date >= LT_Ref->FDate.Date) return(0);
  118.         if (Name->FDate.Date == LT_Ref->FDate.Date
  119.             && Name->FTime.Time >= LT_Ref->FTime.Time) return(0);
  120.         }
  121.     if (LE_Ref != NULL) {
  122.         if (Name->FDate.Date > LE_Ref->FDate.Date) return(0);
  123.         if (Name->FDate.Date == LE_Ref->FDate.Date
  124.             && Name->FTime.Time > LE_Ref->FTime.Time) return(0);
  125.         }
  126.     if (GT_Ref != NULL) {
  127.         if (Name->FDate.Date <= GT_Ref->FDate.Date) return(0);
  128.         if (Name->FDate.Date == GT_Ref->FDate.Date
  129.             && Name->FTime.Time <= GT_Ref->FTime.Time) return(0);
  130.         }
  131.     if (GE_Ref != NULL) {
  132.         if (Name->FDate.Date < GE_Ref->FDate.Date) return(0);
  133.         if (Name->FDate.Date == GE_Ref->FDate.Date
  134.             && Name->FTime.Time < GE_Ref->FTime.Time) return(0);
  135.         }
  136.     if (LT_DateRef != NULL)
  137.         if (Name->FDate.Date >= LT_DateRef->FDate.Date) return(0);
  138.     if (LE_DateRef != NULL)
  139.         if (Name->FDate.Date > LE_DateRef->FDate.Date) return(0);
  140.     if (GT_DateRef != NULL)
  141.         if (Name->FDate.Date <= GT_DateRef->FDate.Date) return(0);
  142.     if (GE_DateRef != NULL)
  143.         if (Name->FDate.Date < GE_DateRef->FDate.Date) return(0);
  144.     return(Result);
  145.     }
  146.  
  147.  void
  148. Action (INFO_BLOCK *Name) {
  149.     extern char AttrOnMask, AttrOffMask;
  150.     extern int PrtSwt, LsSwt, LdSwt, RmSwt, RmSwtA, SumSwt;
  151.     extern int AttrOnSwt, AttrOffSwt, CopySwt, MoveSwt, ExecSwt, RelSwt;
  152.     extern long TotalSize;
  153.  
  154.     static char *MonthTab[] = {
  155.         "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
  156.         "Oct", "Nov", "Dec"
  157.         };
  158.  
  159.     if (SumSwt) TotalSize += Name->Size;
  160.     if (PrtSwt) printf("%s\n", (RelSwt) ? &Name->Name[BaseLength] : Name->Name);
  161.     if (LsSwt || LdSwt) {
  162.         printf("%c%c%c%c%c%c",
  163.             Name->Attrib & FA_ARCH   ? 'a' : '-',    /* for the archive bit being on */
  164.             Name->Attrib & FA_DIREC  ? 'd' : '-',    /* for the directory bit being on */
  165.             Name->Attrib & FA_LABEL  ? 'v' : '-',    /* for the file being a volume label */
  166.             Name->Attrib & FA_SYSTEM ? 's' : '-',    /* the for file being a system file */
  167.             Name->Attrib & FA_HIDDEN ? 'h' : '-',    /* for the file being hidden */
  168.             Name->Attrib & FA_RDONLY ? '-' : 'w'    /* for the file being read-only */
  169.             );
  170.         if (Name->Attrib & FA_DIREC) printf("                  ");
  171.         else printf(" %16s ", PrintNumber(Name->Size));
  172.         if (LsSwt) printf("%2u-%3s-%02u ", Name->FDate.d.day,
  173.             MonthTab[Name->FDate.d.month - 1], Name->FDate.d.year+80);
  174.         else printf("%02u-%02u-%02u ", Name->FDate.d.year+80,
  175.             Name->FDate.d.month, Name->FDate.d.day);
  176.         printf("%2u:%02u %s\n", Name->FTime.t.Hour, Name->FTime.t.Minute,
  177.             Name->Name);
  178.         }
  179.     if (AttrOnSwt) {
  180.         printf("ATTR_ON: %s\n", Name->Name);
  181.         _chmod(Name->Name, 1, AttrOnMask | Name->Attrib);
  182.         }
  183.     if (AttrOffSwt) {
  184.         printf("ATTR_OFF: %s\n", Name->Name);
  185.         _chmod(Name->Name, 1, ~AttrOffMask & Name->Attrib);
  186.         }
  187.     if ( (RmSwt || RmSwtA)
  188.             && !( (Name->Attrib & FA_DIREC) || (Name->Attrib & FA_LABEL) ) ) {
  189.         printf("RM: %s\n", Name->Name);
  190.         if (unlink(Name->Name)) {
  191.             if (!RmSwtA) perror("    FAILED");
  192.             else {
  193.                 chmod(Name->Name, S_IREAD | S_IWRITE);
  194.                 if (unlink(Name->Name)) perror("    FAILED");
  195.                 }
  196.             }
  197.         }
  198.     if ( (CopySwt)
  199.             && !( (Name->Attrib & FA_DIREC) || (Name->Attrib & FA_LABEL) ) ) {
  200.         Copy(Name);
  201.         }
  202.     if ( (MoveSwt)
  203.             && !( (Name->Attrib & FA_DIREC) || (Name->Attrib & FA_LABEL) ) ) {
  204.         Move(Name);
  205.         }
  206.     if (ExecSwt) {
  207.         Execute(Name->Name);
  208.         }
  209.     }
  210.  
  211.  int
  212. CheckPath (QUE_DEF *Q, char *Name) {
  213.     QUE_ENTRY *t;
  214.     char *p1, *p2;
  215.     int Result = 0;
  216.  
  217.     for (t=Q->Head; t != NULL; t = t->Next) {
  218.         p1 = strrchr(Name, '\\');
  219.         p2 = strrchr(t->Body, '\\');
  220.         if (p1 - Name == p2 - t->Body)
  221.             if (Match(Name, t->Body)) {
  222.                 Result = 1;
  223.                 break;
  224.                 }
  225.         }
  226.     return(Result);
  227.     }
  228.  
  229.  void
  230. FixDirRef (char *Name, char *Ref, char *Temp) {
  231.     extern int BaseLength, TreeSwt;
  232.  
  233.     char *p;
  234.  
  235.     if ( (p = strrchr(Name, '\\')) == NULL) p = Name;
  236.     else ++p;
  237.     strcpy(Temp, Ref);
  238.     if (TreeSwt) strcat(Temp, &Name[BaseLength]);
  239.     else strcat(Temp, p);
  240.     }